//

// (  )
//

package com.tools.acceleratecore.xlib.util;

import android.app.ActivityManager;
import android.content.Context;
import android.os.Process;
import android.text.TextUtils;

public class UtilProcess {
    public UtilProcess() {
    }

    public static boolean killBackgroundProcess(Context context, String strPackageName) {
        if (context != null && !TextUtils.isEmpty(strPackageName)) {
            ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
            am.killBackgroundProcesses(strPackageName);
            return true;
        } else {
            return false;
        }
    }

    public static boolean killProcessWithRoot(int nProcessID) {
        return true;
    }

    public static String getProcessNameByPID(int nPID) {
        String strDetailProcessName = UtilIO.readFirstLineInFile("/proc/" + nPID + "/cmdline");
        return strDetailProcessName;
    }

    public static int getMyPID() {
        return Process.myPid();
    }

    public static String getMyPackageName() {
        return null;
    }

    private static String cleanCmdline(String strRaw) {
        if (TextUtils.isEmpty(strRaw)) {
            return null;
        } else {
            for(int i = 0; i < strRaw.length(); ++i) {
                if (Character.isIdentifierIgnorable(strRaw.charAt(i))) {
                    return strRaw.substring(0, i);
                }
            }

            return strRaw;
        }
    }
}
